package com.hsck.order.kds.main.dialog

import android.app.Activity
import android.app.Dialog
import android.view.LayoutInflater
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import com.hsck.order.kds.R
import com.hsck.order.kds.base.utils.setOnSingleClickListener
import com.hsck.order.kds.databinding.NewSiteDialogLayoutBinding

/**
 * 新增站点
 */
class NewSiteDialog(context: Activity) : Dialog(context, R.style.Dialog_FullScreen) {
    private lateinit var onCliclLisener: NewSiteListener
    private val activity: Activity = context

    private var binding: NewSiteDialogLayoutBinding = DataBindingUtil.inflate(
        LayoutInflater.from(context),
        R.layout.new_site_dialog_layout,
        null,
        false
    )

    init {
        createDialog()
    }

    private fun createDialog() {
        setContentView(binding.root)
        setCanceledOnTouchOutside(false)
        setCancelable(false)
        val lp = window?.attributes
        lp?.width = WindowManager.LayoutParams.MATCH_PARENT
        lp?.height = WindowManager.LayoutParams.WRAP_CONTENT

        lp?.alpha = 1f
        window?.attributes = lp
        if (activity.isFinishing) {
            return
        }
        binding.tvNewSite.setOnSingleClickListener {
            dismiss()
            onCliclLisener.onNewSiteListener()
        }
    }

    fun showSite() {
        show()
    }

    fun setNewSiteListener(clickListener: NewSiteListener) {
        this.onCliclLisener = clickListener
    }

    interface NewSiteListener {
        fun onNewSiteListener()
    }
}
